﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using Film8.Models;

namespace Film8.DAL
{
    public class Film8Initializer : DropCreateDatabaseIfModelChanges<Film8Context>
    {
        protected override void Seed(Film8Context context)
        {

            var movies = new List<Movie>
            {
            new Movie{Title="Pulp Fiction",Genre="Crime",Year=1994, MovieFans = new List<Fan>{} },
            new Movie{Title="Matrix",Genre="Sci-Fi",Year=2002, MovieFans = new List<Fan>{} },
            new Movie{Title="Inglourious Basterds",Genre="Action",Year=2009, MovieFans = new List<Fan>{} },
            new Movie{Title="Django",Genre="Western",Year=2012, MovieFans = new List<Fan>{} },
            new Movie{Title="Goodfellas",Genre="Crime",Year=1991, MovieFans = new List<Fan>{} },
            new Movie{Title="Donnie Darko",Genre="Drama",Year=2001, MovieFans = new List<Fan>{} },
            new Movie{Title="The Wolf of Wallstreet",Genre="Crime",Year=2013, MovieFans = new List<Fan>{} },
            new Movie{Title="Jackie Brown",Genre="Crime",Year=1997, MovieFans = new List<Fan>{} },
            new Movie{Title="True Romance",Genre="Crime",Year=1993, MovieFans = new List<Fan>{} }
                       
            };

            movies.ForEach(s => context.Movies.Add(s));
            context.SaveChanges();

            var fans = new List<Fan>
            {
            new Fan{Name="Peled Eldan", Address="56 HaGilgal, Ramat Gan", LikedMovies = new List<Movie>{} },
            new Fan{Name="Daniel Manor", Address="2 Haefroni St, Ramat Hasharon", LikedMovies = new List<Movie>{} },
            new Fan{Name="Albert Einstein", Address="112 Mercer, New Jersey", LikedMovies = new List<Movie>{} },
            new Fan{Name="Dennis Ritchie", Address="600 Mountain Ave. Murray Hill, New Jersey", LikedMovies = new List<Movie>{} },
            new Fan{Name="Steve Jobs", Address="2101 Waverley, Palo Alto", LikedMovies = new List<Movie>{} },
            new Fan{Name="Bill Gates", Address="1835 73rd Ave NE, Medina", LikedMovies = new List<Movie>{} },
            new Fan{Name="Bill Withers", Address="Slab Fork, West Virginia", LikedMovies = new List<Movie>{} },
            new Fan{Name="Walter White", Address="308 Negra Arroyo Lane, Albuquerque", LikedMovies = new List<Movie>{} }
            };

            fans.ForEach(s => context.Fans.Add(s));
            context.SaveChanges();

            var directors = new List<Director>
            {
            new Director{Name="Quentin Tarantino", Movies = new List<Movie>{} },
            new Director{Name="Steven Speilberg", Movies = new List<Movie>{} },
            new Director{Name="Martin Scorsese", Movies = new List<Movie>{} },
            new Director{Name="Tony Scott", Movies = new List<Movie>{} },
            new Director{Name="Richard Kelly", Movies = new List<Movie>{} },
            };

            directors.ForEach(s => context.Directors.Add(s));
            context.SaveChanges();

            directors[0].Movies.Add(movies[0]);
            directors[0].Movies.Add(movies[2]);
            directors[0].Movies.Add(movies[3]);
            directors[0].Movies.Add(movies[8]);
            directors[1].Movies.Add(movies[1]);
            directors[1].Movies.Add(movies[4]);
            directors[2].Movies.Add(movies[5]);
            directors[3].Movies.Add(movies[6]);
            directors[4].Movies.Add(movies[7]);

            fans[0].LikedMovies.Add(movies[2]);
            fans[0].LikedMovies.Add(movies[3]);
            fans[0].LikedMovies.Add(movies[5]);
            fans[1].LikedMovies.Add(movies[1]);
            fans[1].LikedMovies.Add(movies[4]);
            fans[1].LikedMovies.Add(movies[8]);
            fans[2].LikedMovies.Add(movies[1]);
            fans[2].LikedMovies.Add(movies[2]);
            fans[2].LikedMovies.Add(movies[4]);
            fans[2].LikedMovies.Add(movies[5]);
            fans[3].LikedMovies.Add(movies[6]);
            fans[4].LikedMovies.Add(movies[7]);
            fans[5].LikedMovies.Add(movies[1]);
            fans[5].LikedMovies.Add(movies[4]);
            fans[5].LikedMovies.Add(movies[5]);
            fans[5].LikedMovies.Add(movies[6]);
            fans[6].LikedMovies.Add(movies[7]);
            fans[7].LikedMovies.Add(movies[0]);
            fans[7].LikedMovies.Add(movies[2]);
            fans[7].LikedMovies.Add(movies[3]);

            context.SaveChanges();
        }
    }
}